package com.wondertek.poms.core.filter;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

import com.wondertek.poms.dao.po.Content;
import com.wondertek.poms.dao.po.IRulePo;

/**
 * <p><b>PolicyFilterChain Description:</b> 批价规则过滤器链、包含商品包规则、二级产品规则</p>
 * @author douzi
 * <b>DATE</b> 2019年8月5日 下午9:27:13
 */
@Data
public class RuleFilterChain implements IRuleFilter {
	
	/**
	 * <b>Fields</b> filters : 过滤器集合 队列实现
	 */
	private List<IRuleFilter> filters;
	
	/**
	 * <b>Fields</b> flag : 过滤器标记  true:符合规则  false:不符合规则
	 */
	private boolean flag = true;
	
	/**
	 * <b>Fields</b> pos : 过滤器集合下标
	 */
	int pos = 0;
	
	/**
	 * <b>Fields</b> resultStr : 返回提示语
	 */
	private StringBuffer resultStr = new StringBuffer();
	
	public RuleFilterChain() {
		filters = new ArrayList<IRuleFilter>();
	}
	
	public RuleFilterChain addFilter(IRuleFilter filter){
		filters.add(filter);
		return this;
	}

	public void doFilter(IRulePo rule, Content vo, RuleFilterChain chain) {
		if (pos < filters.size()) {
			filters.get(pos ++).doFilter(rule, vo, chain);
			//filters.get(pos ++).doFilter(b, vo, this); //this也是可以的
		}
	}
}
